#!/usr/bin/perl

use 5.010;
use warnings;
my @field;
sub Array()
{
  for($i=0; $i<10; $i++) {
    for($j=0; $j<10; $j++) {
      $field[$i*10 + $j]=0;
    }
  }
}
sub Field()
{

    for($i=0; $i<10; $i++)
    {
      for($j=0; $j<10; $j++)
      {
        if($field[$i*10 + $j]==0)
        {
          print " *";
        }
        else
        {
          print " #";
        }
      }  
      print "\n";
    }
}

Array;
my $flag=0;
foreach my $coord (@ARGV)
{  
  my $x1=substr $coord, 0, 1;
  my $x2 =substr $coord, 2, 1;
  my $y1=substr $coord, 1, 1;
  my $y2=substr $coord, 3, 1;
  my $test1=$x2-$x1;
  my $test2=$y2-$y1;
  my $test3= length $coord;
  if ($test3==4 && $test1<=4 && $test2 <= 4 && ($x1 == $x2 || $y1 == $y2))
  {
    for($i=$x1;$i <= $x2;$i++)
    {
                for($j=$y1;$j <= $y2;$j++)
      {
        if ($field[$i*10 + $j]==1)
        {
          print "There are some collisions with existence ship\n";
          $flag=1;
        }
      }
    }
    if ($flag==1) 
      {  
        $flag=0;
        next;
      }
        for($i=$x1;$i <= $x2;$i++)
    {
                        for($j=$y1;$j <= $y2;$j++)
      {
          $field[$i*10 + $j]=1;
      }
    }
  }
  else
  {
    print "horizontal and vertival ships, less than 4";
  }
}
Field;
